import React, { createRef, PureComponent } from 'react'

class HelloWorld extends PureComponent {
  test() {
    console.log('hello world runing')
  }
  render() {
    return <div>Hello World</div>
  }
}

export default class App extends PureComponent {
  constructor() {
    super()
    this.state = {}

    this.helloworldRef = createRef()
  }
  handleClick() {
    console.log(this.helloworldRef.current)
    this.helloworldRef.current.test()
  }
  render() {
    return (
      <div>
        <HelloWorld ref={this.helloworldRef} />
        <button onClick={() => this.handleClick()}>获取DOM</button>
      </div>
    )
  }
}
